package com.yong.sbd.common.beans.exception;

import lombok.Getter;
import lombok.Setter;

import java.text.MessageFormat;

/**
 * 业务异常定义
 *
 * @author Kang Yong
 * @date 2025/10/22
 * @since 1.0.0
 */
@Getter
@Setter
public class BusinessException extends RuntimeException {

    private Integer code;

    public BusinessException(Integer code, String msg) {
        super(msg);
        this.code = code;
    }

    public BusinessException(String msg) {
        super(msg);
        this.code = CommonExceptionEnum.FAIL.getCode();
    }

    public BusinessException(ExceptionEnum exceptionEnum) {
        super(exceptionEnum.getMsg());
        this.code = exceptionEnum.getCode();
    }

    public BusinessException(ExceptionEnum exceptionEnum, String... msg) {
        super(MessageFormat.format(exceptionEnum.getMsg(), (Object) msg));
        this.code = exceptionEnum.getCode();
    }

}
